package com.jdk.study.d2jvm.chapter05;

/**
 * @description: 说明早期绑定和晚期绑定的例子
 * @author: JackLi
 * @date: 2020/4/12 22:34
 */

class Animal {
    public void eat() {
        System.out.println("动物吃饭");
    }
}

interface Huntable {
    void hunt();
}

class Dog extends Animal implements Huntable {
    @Override
    public void eat() {
        System.out.println("狗吃骨头");
    }

    @Override
    public void hunt() {
        System.out.println("狗拿耗子，多管闲事");
    }
}

class Cat extends Animal implements Huntable {

    public Cat() {
        super();    // 表现为：早期绑定
    }

    public Cat(String name) {
        this(); // 表现为：早期绑定
    }

    @Override
    public void eat() {
        System.out.println("猫吃鱼");
    }

    @Override
    public void hunt() {
        System.out.println("猫抓耗子，天经地义");
    }
}


public class Stack10_AnimalTest {

    public void showAnimal(Animal animal) {
        animal.eat();   // 表现为：晚期绑定
    }

    public void showHunt(Huntable h) {
        h.hunt();   // 表现为：晚期绑定
    }

}
